﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.datatables;

namespace l1cs.server.clientpackets
{
    public class C_CharcterConfig : ClientBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( C_CharcterConfig ).FullName );
        private const String _C_CHARCTER_CONFIG = "[C] C_CharcterConfig";

        public C_CharcterConfig( byte[] abyte0, ClientThread client )
            : base( abyte0 )
        {
            if ( Config.CHARACTER_CONFIG_IN_SERVER_SIDE )
            {
                L1PcInstance pc = client.getActiveChar();
                int length = readD() - 3;
                byte[] data = readByte();
                int count = CharacterConfigTable.getInstance().countCharacterConfig( pc.getId() );
                if ( count == 0 )
                {
                    CharacterConfigTable.getInstance().storeCharacterConfig( pc.getId(), length, data );
                }
                else
                {
                    CharacterConfigTable.getInstance().updateCharacterConfig( pc.getId(), length, data );
                }
            }
        }

        override
        public String getType()
        {
            return _C_CHARCTER_CONFIG;
        }
    }
}